 
$(function(){ 
	//requestMenu();
	init();
	iscroll(); 
	link();
});
//向后台请求菜单数据
function requestMenu(){
	$.ajax({
		url : "selectMenuAll.do",
		type : "post",
		dataType : "json",
		data : {
			method : "selectMenuAll"
		},
		success : function(data){
			if("500600" == data.resultCode){
				//alert("ok");
				
			}else{
				
				
			}
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			//alert(errorThrown);
		}
	}); 
}

//菜单栏初始化
function init(){ 
	var sideMenu = $("#J-SideMenu");
	sideMenu.find("dl").addClass("curr-show");//默认展开菜单栏
	 
	var editPerInfoArea = $("#J-PerInfoEdit");
	var perInfoEditBtn = $("#J-PerInfoEditBtn");
	var showPerInfo = $("#J-ShowPerInfo");
	 
	sideMenu.find(".swtich-menu > dt > .row-webkit-box").on("tap", function(){
	    var parentElem = $(this).parent().parent();
	    parentElem.hasClass("curr-show") ? parentElem.removeClass("curr-show") :  parentElem.addClass("curr-show") ;
		myIscroll.refresh();
		myIscroll.scrollToElement(this,0)
	}) 
} 

function link(){
	//首页
	$("#home").on("tap",function(){
		location.href="/mobile/index.html";
	});
	//查异常
	$("#except").on("tap",function(){
		location.href="/mobile/mywork/ycwork.html";
	});
	//去请假
	$("#leave").on("tap",function(){
		location.href="/mobile/mywork/sqwork.html";
	});
	//请假单
	$("#leaveList").on("tap",function(){
		location.href="/mobile/mywork/qjwork.html";
	});
	//写汇报
	$("#editReport").on("tap",function(){
		//location.href="/mobile/kpi/kpi-todo.html";
		toReport("");
	});
	//审批汇报
	$("#auditReport").on("tap",function(){
		location.href="/mobile/underlingReport/xslb.html";
	});
	//查薪资
	$("#salary").on("tap",function(){
		location.href="/mobile/mysalary/gzd-chaxun.html";
	});
	//易问
	$("#answ").on("tap",function(){
		location.href="/mobile/yzx/yzx.html";
	});
	//马上挣钱
	$("#earn").on("tap",function(){
		location.href="/mobile/myfund/mszq.html";
	});
	//设置
	$("#set").on("tap",function(){
		location.href="/mobile/sz.html";
	});
	
}
 

//页面滚动效果
function iscroll(){
	winH = $(window).height();
   	$("#wrap").height(winH);
	$("#J-SideMenu").height(492);
	myIscroll = new iScroll("J-SideMenu",{bounce:false});
}

//先检测汇报状态,再判断调整页面
function toReport(report_date){
	if(report_date==""){
		var date = new Date();
		var month = date.getMonth()+1;
		if(month<10)
			month="0"+month;
		report_date = date.getFullYear()+"/"+month;
	}
	$.ajax({
		type: "post",
		url: mpsurl+"/mobile/report/queryMyReport.do",
		dataType: "json",
		data:{
			report_date:report_date
		},
		success: function (data) { 
			var obj = eval(data);
			var resultCode = obj.resultCode;
			var resultMessage = obj.resultMessage;
			if(resultCode=="500600"){
				var report = obj.value.report;
				var status =  report.pAIC_MON_STATUS;
				if(status=="USUB" || status=="BAC" || status=="NON"){
			    	location.href="/mobile/kpi/kpi-todo.html?report_date="+report_date;
			    }else{
			    	location.href="/mobile/myreport/wdydbg-chakan.html?report_date="+report_date;
			    }
//			}else if(resultCode=="500611"){
//				//请先制定年度计划
//				location.href="/mobile/myreport/wdydbg-chakan.html?report_date="+report_date;
			}else{
				if(obj.resultCode=="500702" || obj.resultCode=="500802" || obj.resultCode=="500803"){
					checkLogin(obj.resultCode,"/mobile/index.html",resultMessage);
				}else{
					location.href="/mobile/myreport/wdydbg-chakan.html?report_date="+report_date;
				}
			}
		}
	});
}
 